package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    void insertAddress(AddressBook addressBook);


    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> queryList(Long userId);

    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook queryDefault(Long userId);

    void updateAddress(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id};")
    void deleteAddress(Long id);

    @Select("select * from address_book where id = #{id}")
    AddressBook getAddressById(Long id);

    @Update("update address_book set is_default=0 where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
}
